package com.imooc.miaosha.redis;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.data.redis.RedisProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Service;

import redis.clients.jedis.JedisPool;
import redis.clients.jedis.JedisPoolConfig;

import java.lang.management.PlatformLoggingMXBean;

@Service
@Configuration
public class RedisPoolFactory {

    @Autowired
    private RedisProperties redisProperties;

    @Bean
    public JedisPool JedisPoolFactory() {
        JedisPoolConfig poolConfig = new JedisPoolConfig();
        poolConfig.setMaxTotal(2000);
        poolConfig.setMaxIdle(500);
        poolConfig.setMaxWaitMillis(1000);
        JedisPool jp = new JedisPool(poolConfig, redisProperties.getHost(),
                redisProperties.getPort(),
                Integer.parseInt(Long.toString(redisProperties.getTimeout().getSeconds())),
                redisProperties.getPassword());
        return jp;
    }

}
